import random

def ip_create():
    # global ipshow
    # ipshow = 0
    with open("ips.txt","w+") as fp:
        for i in range(1200):
            str1 = random.randint(1,255)
            ip = f'172.25.254.{str1}'
            fp.write(ip + '\n')
#执行文本函数
ip_create()

#新建字典
ip_alive = {}
with open("ips.txt", "r+") as fp:
    # ipshow = fp.readlines()
    #172.168.0.254
   for ip in fp:
       ip_alive[ip] =ip_alive.get(ip,0) +1
    #检验IP是否在字典中
    #{“172.168.25.254”：1}
    # if ip in ip_alive:
    #     ip_alive[ip] +=1
    # else:
    #     ip_alive[ip] = 1

      #字典排序
result =sorted(ip_alive.items(),key=lambda x: x[1], reverse=True)[:10]
print(f"前十是：{result}" )
